import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../layout' //布局页

Vue.use(VueRouter)
//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    meta: {
      title: "首页",
      icon: 'el-icon-s-home',
    },
    name: 'index',
    children: [
      {
        path: 'index',
        name: 'index',
        component: () => import('@/views/home.vue'),
        meta: {
          title: "首页",
        }
      },
    ]
  },
  {
    // 比价表
    path: '/monthlyBidding',
    component: Layout,
    meta: {
      title: "月度比价记录",
      icon: 'el-icon-s-custom',
    },
    name: 'monthlyBidding',
    children: [
      {
        path: 'monthlyBidding',
        name: 'monthlyBidding',
        component: () => import('@/views/monthlyBidding/index.vue'),
        meta: {
          title: "月度比价记录",
          icon: 'el-icon-s-custom',
        }
      }
    ]
  },
  {
    // 供应商管理
    path: '/supplier',
    component: Layout,
    meta: {
      title: "供应商管理",
      icon: 'el-icon-s-custom',
    },
    name: 'supplier',
    children: [
      {
        path: 'supplier',
        name: 'supplier',
        component: () => import('@/views/supplier/index.vue'),
        meta: {
          title: "供应商管理",
          icon: 'el-icon-s-custom',
        }
      }
    ]
  },
  {
    // 采购员管理
    path: '/purchaser',
    component: Layout,
    meta: {
      title: "采购员管理",
      icon: 'el-icon-s-custom',
    },
    name: 'purchaser',
    children: [
      {
        path: 'purchaser',
        name: 'purchaser',
        component: () => import('@/views/purchaser/index.vue'),
        meta: {
          title: "采购员管理",
          icon: 'el-icon-s-custom',
        }
      }
    ]
  },
  {
    // 每日采购单管理
    path: '/dailyMenu',
    component: Layout,
    meta: {
      title: "每日采购单",
      icon: 'el-icon-s-order',
    },
    name: 'dailyMenu',
    children: [
      {
        path: 'dailyMenu',
        name: 'dailyMenu',
        component: () => import('@/views/dailyMenu/index.vue'),
        meta: {
          title: "每日采购单",
          icon: 'el-icon-s-order',
        }
      }
    ]
  },
  {
    // 菜品评价选项管理
    path: '/dishRating',
    component: Layout,
    meta: {
      title: "菜品评价选项",
      icon: 'el-icon-star-on',
    },
    name: 'dishRating',
    children: [
      {
        path: 'dishRating',
        name: 'dishRating',
        component: () => import('@/views/dishRating/index.vue'),
        meta: {
          title: "菜品评价选项",
          icon: 'el-icon-star-on',
        }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    meta: {
      title: "系统管理",
      icon: 'el-icon-s-custom',
    },
    name: 'system',
    children: [
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/system/user/index.vue'),
        meta: {
          title: "用户管理",
        }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/system/role/index.vue'),
        meta: {
          title: "角色管理",
        }
      },
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/system/menu/index.vue'),
        meta: {
          title: "菜单管理",
        }
      },

    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
